<?php
$javascript->link('/deals/js/camera.js',false);
if(!isset($appHtml))
{
	$html->initHelper('AppHtml');
	$appHtml = $html->AppHtml;
}
$currencySymbol = cr("DealConfig.currency_symbol");
?>
<section class="hauptseite deals_detail">
	<div class="container">
		<div class="row">
			<div class="row_detail">
				<div class="col-md-8 col_left">
					<div class="bg_black">
						<div class="each_line">
							<div class="image" align="center"> 
							<?php if(isset($deal['DealAsset']) && !empty($deal['DealAsset'])){?>
								<?php if(count($deal['DealAsset'])>1) { ?>
									<div class="fr camera_wrap" id="deal_slideshow">
										<?php foreach ($deal['DealAsset'] as $dealAsset) { ?>
										<div data-src="<?php echo $dealAsset['file_url'];?>"></div>
										<?php } ?>
									</div>
								<?php } else {?>
									<div class="image" align="center">
										<?php echo $html->image($deal['DealAsset'][0]['file_url'],array('thumb'=>array('crop'=>false,'width'=>'630','height'=>'400'),'class'=>'thumbnail','alt'=>sprintf(__("%s picture"),$deal['Deal']['title'])));?>
									</div>
								<?php } ?>
							<?php }?>
							</div>
						</div>
						<div class="each_line padd deal_description">
							<h2 class="h2_title_detail"><?php echo __($deal['Deal']['title']); ?></h2>
							<div class="unit firstUnit">
								<?php 
								if(strlen($deal['Deal']['description']))
								{
									echo "<h3>".__("Highlights")."</h3>";
									echo $deal['Deal']['description'];
								}
								?>
								<?php 
								if(strlen($deal['Deal']['validity']))
								{
									echo "<h3>".__("Validity")."</h3>";
									echo $appHtml->flayText($deal['Deal']['validity'],150);
								}
								?>
								<?php 
								if(strlen($deal['Deal']['fine_print']))
								{
									echo "<h3>".__("Fine Print")."</h3>";
									echo $deal['Deal']['fine_print'];
								}
								?>
								<?php 
								if(strlen($deal['Deal']['terms']))
								{
									echo "<h3>".__("Terms")."</h3>";
									echo $appHtml->flayText($deal['Deal']['terms'],150);
								}
								?>
							</div>
						</div>
						<!--deal_description-->
						<div class="each_line listing_details">
							<h3><?php echo __("Business Information"); ?></h3>
							<?php if($deal['Listing']['id'] == '')  { ?>
								This business listing has been deleted from our database.
							<?php } else { ?>
								<div class="left_info">
								<?php 
								$listingImage = $html->image($deal['Listing']['image'],array('thumb'=>array('crop'=>true,'width'=>68,'height'=>68),"class"=>"img-circle",'alt'=>sprintf(__("%s"),$deal['Listing']['title'])));
								echo $html->link("<div class='image'>".$listingImage."</div>",$html->url($deal['Listing']['viewUrl']),array("target"=>"_blank","escape"=>false));
								?>
								</div>
								<div class="right_info"> 
								<?php 
								echo $html->link("<div class='title'>".$deal['Listing']['title']."</div>",$html->url($deal['Listing']['viewUrl']),array("target"=>"_blank","escape"=>false));
								?>
								<?php 
								echo $html->link(__("Click here to see more business information"),$html->url($deal['Listing']['viewUrl']),array("target"=>"_blank","escape"=>false));
								?>
								</div>
							<?php }?>
						</div>
						<!--listing_details--> 
					</div>
					<!--bg_black--> 
				</div>
				<!--col_left-->
				
				<div class="col-md-4 col_right">
					<div class="bg_black box_deal">
						<div class="deal_left">
							<div class="counter">
								<?php 
								$dealIsOn = false;
								if(($deal['Deal']['total_quantity']==0) || ($deal['Deal']['total_quantity']>$deal['Deal']['quantity_consumed'])) {
									$dealIsOn = true;
								?>
								<div class="countdownTimer contentBoxLeft">
									<div class="countdownTimerBox"> 
										<i class="ico icoHourGlass"></i> 
										<span class="jtimeLeft timeLeft"> 
											<span class="countdownLabel"> <?php echo __("This deal will run the next",true); ?>: </span> 
											<span class="countdownTime">
												<span class="daysLeft">-</span>
												<span class="dayLabel"> days </span>
												<span class="hoursLeft">-</span>:<span class="minutesLeft">-</span>:<span class="secondsLeft">-</span> 
											</span>
											<input type="hidden" class="jcurrentTimeLeft" value="<?php echo $differenceInMilliSeconds; ?>" />
										</span>
									</div>
								</div>
								<script type="text/javascript">
								$(function() {$('.jtimeLeft').dealCountdown(1, "<?php echo __("day")?>","<?php echo __("days")?>");});
								</script>
								<?php }	else {?>
								<div class="soldOutBanner"><?php echo __("SOLD OUT"); ?></div>
								<?php }?>
							</div>
							
							<?php if($showBuyButton) { ?>
							<!--counter-->
							<div class="count">
								<div id="contentDealStatusBox" class="contentBoxLeft">
									<div class="soldAmount">
										<span id="jDealSoldAmount">
										<?php
										$qty_cons = $deal['Deal']['quantity_consumed'];
										$available = $deal['Deal']['total_quantity'];
										$msg = $qty_cons;
										if($available>0)
										{
											$msg = $qty_cons . __(" out of ") . $available;
										}
										echo $msg;
										?>
										</span> <?php echo __("Bought!")?> 
									</div>
									<div id="dealSuccessful" class="dealSuccessful"> <span id="dealTookPlace" style="display: none"><?php echo __("The %s was completed!"); ?></span>
										<div id="dealTakePlace"> <i class="big bigDealCheck"></i><?php echo __("Deal is on!"); ?></div>
									</div>
									<div id="dealUnsuccessful" class="dealUnsuccessful">
										<div id="dealUnsuccessfulText" style="display: none"> <i class="big bigDealCheck"></i><?php echo __("Deal is finished"); ?></div>
									</div>
								</div>
							</div>
							<!--count-->
							<div class="amt">
								<?php 
								$deal['Deal']['finalPrice'] = str_replace(",", "", $deal['Deal']['finalPrice']);
								echo __("Amount").": ".$currencySymbol."".number_format($deal['Deal']['finalPrice'],2,'.',''); ?>
							</div>
							<div class="line save">
								<div class="unit size1of3 first"> <span><?php echo __("Regular Price");?></span> <br>
									<?php echo $currencySymbol ."". $deal['Deal']['regular_price']; ?> </div>
								<div class="unit size1of3"> <span><?php echo __("Discount");?></span> <br>
									<?php echo $discount."%"; ?> </div>
								<div class="unit size1of3"><span><?php echo __("You save");?></span><br>
									<?php echo $currencySymbol ."". $saving; ?> </div>
							</div>
							<!--save-->
							<div class="w_btn_buy">
								<?php
									$btn_text = '<div class="buybtn">'.__("Buy now").'</div>'; 
									echo $html->link($btn_text,array("plugin"=>"deals","controller"=>"deal_orders","action"=>"add",$deal['Deal']['id']),array('class'=>'','escape'=>false));
								?>
							</div>
							<?php } ?>
							<div class="share_actions"> <span><?php echo __("Share with friends"); ?></span><br>
								<script type="text/javascript">var switchTo5x=true;</script>
								<script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>
								<script type="text/javascript">stLight.options({publisher: "fa18b95c-f879-47b6-875f-0b41ebda6416", doNotHash: true, doNotCopy: true, hashAddressBar: false});</script>
								<span class='st_facebook' displayText='Facebook'></span>
								<span class='st_twitter' displayText='Twitter'></span>
								<span class='st_email' displayText='eMail'></span>
							</div>
							<!--share_actions--> 
							
						</div>
						<!--deal_left--> 
					</div>
					<!--bg_black--> 
				</div>
				<!--col_right--> 
				
			</div>
			<!--/.row_detail --> 
		</div>
		<!--/.row--> 
	</div>
	<!--/.container--> 
</section>
<!-- /.hauptseite--> 
<script>
$(document).ready(function(){
	$("#deal_slideshow").camera({
		portrait: true,
		transPeriod: 1500,
		time: 4000,
		fx: 'scrollRight',
		loader: 'none',
		'height' : '330px',
		//'loader' : 'bar',
		'pagination' : false,
		//'thumbnails' : true
	});
	
});
</script>

<script>
(function ($) {
    $.fn.dealCountdown = function (params) {
        var args = Array.prototype.slice.call(arguments);
        return this.each(function () {
            new $.DealCountdown(this, args);
        });
    };
    $.DealCountdown = function (obj, options) {
        var timerTimeLeft = 0;
        var currentTimeLeft = 0;
        var secondsForTimer = 1000;
        var singleDayLabel = "day";
        var pluralDayLabel = "days";
        var timerType = 2;
        currentTimeLeft = $(obj).find('.jcurrentTimeLeft').val();
        timerType = options[0]
        if (timerType === 1) {
            singleDayLabel = options[1];
            pluralDayLabel = options[2];
        }
        setInitialDealTimer(obj);
        timerTimeLeft = setInterval(function () {
            setDealTimer(obj);
        }, secondsForTimer);

        function setDealTimer(obj) {
            currentTimeLeft = parseInt(currentTimeLeft - secondsForTimer);
            if (currentTimeLeft <= 0) {
                if (timerType === 1) {
                    $(obj).find('.daysLeft').empty();
                    $(obj).find('.dayLabel').empty();
                }
                $(obj).find('.hoursLeft').empty().append("00");
                $(obj).find('.minutesLeft').empty().append("00");
                $(obj).find('.secondsLeft').empty().append("00");
                clearInterval(timerTimeLeft);
            } else {
                displayTimes(obj, currentTimeLeft);
            }
        };

        function setInitialDealTimer(obj) {
            if (currentTimeLeft <= 0) {
                clearInterval(timerTimeLeft);
            } else {
                displayTimes(obj, currentTimeLeft);
            }
        };

        function displayTimes(obj, remainingMilliseconds) {
            var wholeSeconds = parseInt(currentTimeLeft / 1000);
            var wholeMinutes = parseInt(currentTimeLeft / 60000);
            var wholeHours = parseInt(wholeMinutes / 60);
            var seconds = parseInt(wholeSeconds % 60);
            var minutes = parseInt(wholeMinutes % 60);
            var days = parseInt(wholeHours / 24);
            var hours = parseInt(wholeHours % 24);
            if (timerType === 1) {
                if (days > 0) {
                    $(obj).find('.daysLeft').empty().append(days);
                    if (days === 1) {
                        $(obj).find('.dayLabel').empty().append(" " + singleDayLabel + " ");
                    } else if (days > 1) {
                        $(obj).find('.dayLabel').empty().append(" " + pluralDayLabel + " ");
                    }
                } else {
                    $(obj).find('.daysLeft').empty();
                    $(obj).find('.dayLabel').empty()
                }
            }
            if (timerType === 0) {
                hours = wholeHours;
            }
            if (hours < 10) {
                $(obj).find('.hoursLeft').empty().append("0" + hours);
            } else {
                $(obj).find('.hoursLeft').empty().append(hours);
            }
            if (minutes < 10) {
                $(obj).find('.minutesLeft').empty().append("0" + minutes);
            } else {
                $(obj).find('.minutesLeft').empty().append(minutes);
            }
            if (seconds < 10) {
                $(obj).find('.secondsLeft').empty().append("0" + seconds);
            } else {
                $(obj).find('.secondsLeft').empty().append(seconds);
            }
        };
    }
})(jQuery);
</script>